
const { globalData } = getApp();
import queryRequest from "./http"
let isAddBuy = false;
const goTargetUrlFn = (params, _that) => {
    // console.log('==========goTargetUrlFn==========', params);
    const { href } = params;
    // console.log(href)
    if (href.includes('http')) {
        my.call("navigateToOutside", {
            url: href
        })
    } else {
        my.navigateTo({
            url: href
        })
    }
}

const addBuyFn = (params, _that) => {
    // console.log(_that,'==========addCart==========', params);

    const { addBuyId } = params;
    if (!isAddBuy) {
        isAddBuy = true;
        my.tb.showSku({
            itemId: addBuyId,
            complete: result => {
                isAddBuy = false;
            }
        })
    }
}
let selectcolor = "";
const customFn = (params, _that) => {
    console.log('----------customFn---------', params)
    const { custom, customData, href } = params;
    console.log(custom, customData, href)
}
const onTapEvent = (params) => {
    const { item, id, _that } = params
    console.log('params', item)
    if (params.item.custom == "showRuleFun") {
        globalData._refs['name_规则部分'].show();
    } else if (params.item.custom == "hideRule") {
        globalData._refs['name_规则部分'].hide();
    }
    trackFun(id);
    switch (item.details) {
        case "goDetails":
            goTargetUrlFn(item, _that);
            break;
        case "addBuy":
            addBuyFn(item, _that)
            break;
        case "custom":
            customFn(item, _that)
            break;
        default: null
    }
}
const trackFun = (data) => {
    var info = {
        version: "v2",
        projectCode: '申请到的pid',
        timestamp: new Date().getTime().toString(),
        province: "",
        city: "",
        customType: data,
        origin: "taobao",
        userId: globalData.username,
        type: null
    }
    // console.log('info',info)
    // queryRequest(info);
}
export default onTapEvent;